<?php

namespace Backoffice\Model\Entity;

use Doctrine\ORM\Mapping as ORM;
use Zend\InputFilter\InputFilterInterface;

/**
 * Produit
 *
 * @ORM\Table(name="produit", indexes={@ORM\Index(name="FK_Produit_Categorie", columns={"id_categorie"}), @ORM\Index(name="FK_Produit_Boutique", columns={"id_boutique"}), @ORM\Index(name="FK_Produit_Etat", columns={"id_etat"})})
 * @ORM\Entity
 */
class Produit
{
	
	protected $inputFilter;
	
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="libelle", type="string", length=30, nullable=true)
     */
    private $libelle;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="text", nullable=true)
     */
    private $description;

    /**
     * @var string
     *
     * @ORM\Column(name="taille", type="string", length=30, nullable=true)
     */
    private $taille;

    /**
     * @var float
     *
     * @ORM\Column(name="prix", type="float", precision=10, scale=0, nullable=true)
     */
    private $prix;

    /**
     * @var integer
     *
     * @ORM\Column(name="date_fin", type="integer", nullable=true)
     */
    private $dateFin;

    /**
     * @var \Backoffice\Model\Entity\Categorie
     *
     * @ORM\ManyToOne(targetEntity="Backoffice\Model\Entity\Categorie")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_categorie", referencedColumnName="id")
     * })
     */
    private $categorie;
    
    /**
     * @var \Backoffice\Model\Entity\Boutique
     *
     * @ORM\ManyToOne(targetEntity="Backoffice\Model\Entity\Boutique")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_boutique", referencedColumnName="id")
     * })
     */
    private $boutique;

    /**
     * @var \Backoffice\Model\Entity\Etat
     *
     * @ORM\ManyToOne(targetEntity="Backoffice\Model\Entity\Etat")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_etat", referencedColumnName="id")
     * })
     */
    private $etat;

    /**
     * @ORM\ManyToMany(targetEntity="Backoffice\Model\Entity\Image", cascade={"persist", "merge"})
     * @ORM\JoinTable(
     *      name="image_produit",
     *      inverseJoinColumns={@ORM\JoinColumn(name="id_image", referencedColumnName="id")},
     *      joinColumns={@ORM\JoinColumn(name="id_produit", referencedColumnName="id")}
     * )
     */
    private $images;
    
    /**
     * Constructor
     */
    public function __construct($id = null, $libelle = null, $description = null, $taille = null, $prix = null,
            $dateFin = null, $categorie = null, $boutique = null, $etat = null)
    {
        $this->id = $id;
        $this->libelle = $libelle;
        $this->description = $description;
        $this->taille = $taille;
        $this->prix = $prix;
        $this->dateFin = $dateFin;
        $this->categorie = $categorie;
        $this->boutique = $boutique;
        $this->etat = $etat;
        
        $this->images = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set libelle
     *
     * @param string $libelle
     * @return Produit
     */
    public function setLibelle($libelle)
    {
        $this->libelle = $libelle;

        return $this;
    }

    /**
     * Get libelle
     *
     * @return string 
     */
    public function getLibelle()
    {
        return $this->libelle;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Produit
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set taille
     *
     * @param string $taille
     * @return Produit
     */
    public function setTaille($taille)
    {
        $this->taille = $taille;

        return $this;
    }

    /**
     * Get taille
     *
     * @return string 
     */
    public function getTaille()
    {
        return $this->taille;
    }

    /**
     * Set prix
     *
     * @param float $prix
     * @return Produit
     */
    public function setPrix($prix)
    {
        $this->prix = $prix;

        return $this;
    }

    /**
     * Get prix
     *
     * @return float 
     */
    public function getPrix()
    {
        return $this->prix;
    }

    /**
     * Set dateFin
     *
     * @param integer $dateFin
     * @return Produit
     */
    public function setDateFin($dateFin)
    {
        $this->dateFin = $dateFin;

        return $this;
    }

    /**
     * Get dateFin
     *
     * @return integer 
     */
    public function getDateFin()
    {
        return $this->dateFin;
    }

    /**
     * Set categorie
     *
     * @param \Backoffice\Model\Entity\Categorie $categorie
     * @return Produit
     */
    public function setCategorie(\Backoffice\Model\Entity\Categorie $categorie = null)
    {
        $this->categorie = $categorie;

        return $this;
    }

    /**
     * Get categorie
     *
     * @return \Backoffice\Model\Entity\Categorie 
     */
    public function getCategorie()
    {
        return $this->categorie;
    }

    /**
     * Set boutique
     *
     * @param \Backoffice\Model\Entity\Boutique $boutique
     * @return Produit
     */
    public function setBoutique(\Backoffice\Model\Entity\Boutique $boutique = null)
    {
        $this->boutique = $boutique;

        return $this;
    }

    /**
     * Get boutique
     *
     * @return \Backoffice\Model\Entity\Boutique 
     */
    public function getBoutique()
    {
        return $this->boutique;
    }

    /**
     * Set etat
     *
     * @param \Backoffice\Model\Entity\Etat $etat
     * @return Produit
     */
    public function setEtat(\Backoffice\Model\Entity\Etat $etat = null)
    {
        $this->etat = $etat;

        return $this;
    }

    /**
     * Get etat
     *
     * @return \Backoffice\Model\Entity\Etat 
     */
    public function getEtat()
    {
        return $this->etat;
    }
    
        /**
     * Add image
     *
     * @param \Backoffice\Model\Entity\Image $image
     * @return Produit
     */
    public function addImage(\Backoffice\Model\Entity\Image $image)
    {
        $this->images[] = $image;

        return $this;
    }

    /**
     * Remove image
     *
     * @param \Backoffice\Model\Entity\Image $image
     */
    public function removeImage(\Backoffice\Model\Entity\Image $image)
    {
        $this->images->removeElement($image);
    }

    /**
     * Get images
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getImages()
    {
        return $this->images;
    }
    
    public function setInputFilter(InputFilterInterface $inputFilter)
    {
        throw new \Exception("Not used");
    }
    
    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $inputFilter = new \Zend\InputFilter\InputFilter();
            $factory     = new \Zend\InputFilter\Factory();

            $inputFilter->add($factory->createInput(array(
                'name'     => 'id',
                'required' => true,
                'filters'  => array(
                    array('name' => 'Int'),
                ),
            )));

            $inputFilter->add($factory->createInput(array(
                'name'     => 'libelle',
                'required' => true,
                'filters'  => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min'      => 1,
                            'max'      => 100,
                        ),
                    ),
                ),
            )));

            $this->inputFilter = $inputFilter;
        }

        return $this->inputFilter;
    }
    
    public function getArrayCopy()
    {
        return get_object_vars($this);
    }
    
    public function populate($data = array()) 
    {
        $this->id = $data['id'];
        $this->libelle = $data['libelle'];
    }
}
